package com.example.permission.common.result;

import lombok.Getter;

/**
 * 响应码枚举
 */
@Getter
public enum ResultCode {
    /**
     * 响应码枚举
     */
    SUCCESS("00000", "system.success"),
    FAIL("A1001", "system.fail"),
    HEADER_INVALID("A1002", "system.header.invalid"),
    TOKEN_INVALID("A1003", "system.token.invalid"),
    USER_EXISTS("A1005", "system.user.already.exists"),
    USER_HAS_ACCESS("A1006", "system.user.no.roles"),
    SYSTEM_TIMEOUT("A1007", "system.timeout"),
    SYSTEM_SIGN_ERROR("A1008", "system.sign.error"),
    APP_INFO_ERROR("A1009", "system.app.info.error"),
    UNKNOWN("B9999", "system.error"),
    ;

    private String code;
    private String message;

    ResultCode(String code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据状态码获取状态码描述
     *
     * @param code 状态码
     * @return String 状态码描述
     */
    public static String getMessage(Integer code) {
        String result = null;
        for (ResultCode r : ResultCode.values()) {
            if (r.code.equals(code)) {
                result = r.message;
            }
        }
        return result;
    }
}
